package com.ruibang.glass.quality.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruibang.glass.quality.entity.EngineeringChangeOrder;
import com.ruibang.glass.quality.service.EngineeringChangeOrderService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import com.teaming.cloud.framework2.common.pojo.PageRequest;
import com.teaming.cloud.framework2.common.pojo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 工程变更单信息 前端控制器
 * </p>
 *
 * @author wujie
 * @since 2024-01-23
 */
@RestController
@RequestMapping("/api/engineering/change/order")
@Api(value="工程变更单信息控制类",tags={"工程变更单信息操作接口"})
public class EngineeringChangeOrderController {
    
    @Autowired
    private EngineeringChangeOrderService engineeringChangeOrderService;

    
    /**
    * 通过id查询
    */
    @GetMapping("/getById/{changeOrderId}")
    @ApiOperation(value="获取工程变更单",notes="获取工程变更单")
    public ResultBody getById(@PathVariable(value = "changeOrderId") String changeOrderId){
        return ResultBody.success(engineeringChangeOrderService.getDetail(changeOrderId));
    }

    /**
    * 新增
    */
    @PostMapping("/save")
    @ApiOperation(value="新增工程变更单",notes="新增工程变更单")
    public ResultBody save(@RequestBody EngineeringChangeOrder engineeringChangeOrder){
        engineeringChangeOrderService.saveInfo(engineeringChangeOrder);
        return ResultBody.success();
    }


    @GetMapping("/getChangeCode")
    @ApiOperation(value="获取变更单code",notes="获取变更单code")
    public ResultBody getChangeCode(){
        return ResultBody.success(engineeringChangeOrderService.getChangeCode());
    }

    /**
    * 通过id删除
    */
    @GetMapping("/deleteById/{id}")
    @ApiOperation(value="通过ID删除工程变更单",notes="通过ID删除工程变更单")
    public ResultBody delete(@PathVariable(value = "id") String ids){
        String[] list = ids.split(",");
        for (String id : list){
            engineeringChangeOrderService.removeById(id);
        }
        return ResultBody.success();
    }

    /**
    * 修改
    */
    @PostMapping("/update")
    @ApiOperation(value="修改工程变更单",notes="修改工程变更单")
    public ResultBody updateInfo(@RequestBody EngineeringChangeOrder engineeringChangeOrder){
        engineeringChangeOrderService.updateInfo(engineeringChangeOrder);
        return ResultBody.success();
    }


    /**
    * 查询列表
    */
   /* @PostMapping("/list")
    @ApiOperation(value="非分页列表查询工程变更单",notes="非分页列表查询工程变更单")
    public ResultBody list(@RequestBody EngineeringChangeOrderReqVo engineeringChangeOrder ){
    final LambdaQueryWrapper<EngineeringChangeOrder> lambda = new QueryWrapper<EngineeringChangeOrder>().lambda();
        this.buildCondition(lambda,engineeringChangeOrder);
        return ResultBody.success(engineeringChangeOrderService.list(lambda));
    }*/

    /**
    * 分页查询
    */
    @PostMapping("/page")
    @ApiOperation(value="分页列表查询工程变更单",notes="分页列表查询工程变更单")
    public ResultBody page(@RequestBody PageRequest<EngineeringChangeOrder> pageParam){
        return ResultBody.success(engineeringChangeOrderService.queryPage(pageParam));
    }



}
